package com.ocl.www.service;


import java.sql.SQLException;
import java.util.List;

import com.ocl.www.config.TargetDataSource;

import com.ocl.www.domain.UserFans;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import com.ocl.www.domain.User;
import com.ocl.www.mapper.UserMapper;

@Service
public class UserService {
	
	@Autowired
	private UserMapper userMapper;
	/**
	 * 
	 * @Title: UserService
	 * @Description: 查询用户信息
	 * @param: @param user
	 * @param: @return
	 * @param: @throws Exception
	 * @return: User
	 * @throws
	 */
	public User findUserInfo (User user)  throws Exception {
		
			return userMapper.selectUserInfo(user);
	
	}
	/**
	 * 
	 * @Title: UserService
	 * @Description: 登录时添加用户基本信息
	 * @param: @param user
	 * @param: @return
	 * @param: @throws Exception
	 * @return: User
	 * @throws
	 */
	public Integer addUserInfo (User user)  throws Exception {
		
			
			try {
				return userMapper.addUserInfo(user);
			} catch (Exception e) {
				throw new RuntimeException(e.getMessage());
			}
	}
	
	/**
	 * @Description: 检验指定账号是否唯一
	 * @param userName
	 * @return
	 * @throws Exception
	 */
	public Integer QueryUsernameIsUnique (String userName)  throws Exception {
		try {
			return userMapper.QueryUsernameIsUnique(userName);
		} catch (Exception e) {
			throw new RuntimeException(e.getMessage());
		}
	}
	
	
	/**
	 * @Description: 注册用户 
	 * @param user
	 * @return
	 * @throws Exception
	 */
	public Integer insertUser(User user) throws Exception{
		int c =  0;
		try {
			c =  userMapper.insertUser(user);
		} catch (Exception e) {
			throw new RuntimeException(e.getMessage());
		}
		return c;
		
		
	}
	public int updateUserInfo(User user) throws Exception {
		// TODO Auto-generated method stub
		
		
    	int c = 0;
	   
	    	c = userMapper.updateUserInfo(user);
		
		return c;
	}
	public int updateEmail(User user) {
		// TODO Auto-generated method stub
		int c = 0;
	    try {
	    	c = userMapper.updateEmail(user);
		} catch (Exception e) {
			throw new RuntimeException(e.getMessage());
		}
		return c;
	}

	public int updateUserheadImg(User user) {
		// TODO Auto-generated method stub
		int c = 0;
	    try {
	    	c = userMapper.updateUserheadImg(user);
		} catch (Exception e) {
			throw new RuntimeException(e.getMessage());
		}
		return c;
	}

    public List<User> selectUsers() throws  Exception{

		return userMapper.selectUsers();

    }

	public List<User> selectFansForUser(User user)  throws  Exception{

		return userMapper.selectFansForUser(user);
	}

	public List<User> getFollows(UserFans userFans) throws SQLException{
		return userMapper.getFollows(userFans);

	}

	public List<User> getFans(UserFans userFans) throws SQLException {
		return userMapper.getFans(userFans);
	}


    public User findUserInfo2(User user)throws SQLException  {

		return userMapper.selectUserInfo(user);

    }
}
